<extend name="Public:index" />
<block name="main-crumb">
    <li class="active">传感器类型</li>
</block>
<block name="mycss">
     
        <style>
        .state_text{
            vertical-align: -webkit-baseline-middle;  
        }
        </style>
    </block>
<block name="main-content">
    <div class="container-fluid">


        <div class="card">
            <form class="" action="{:U('sensor_list')}" method="post">
                <div class="card-body ">
                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group row">
                                <label for="example-text-input" class="col-sm-4 col-form-label text-right">末端设备名称</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="sensor_name" name='sensor_name' value="{$sensor_name}">
                                </div>
                                <div class="col-sm-2">
                                    <input type="submit" class="btn btn-primary waves-effect waves-light" id="searth"
                                        value="搜索" />

                                </div>
                            </div>

                        </div>
                        <div class="col-md-8">
                         <label for="example-text-input" class="col-sm-12 col-form-label text-right"><a  class="btn btn-primary" href="{:U('sensor_add')}">添加传感器</a></label>
                        
                        </div>
                    

                    </div>

                </div>
            </form>
        </div>
        <!--end card-body-->



        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <table id="sort" class="table table-bordered table-centered">
                            <thead>
                                <tr>
                                    <!--<th>编号</th>-->
                                    <th>排序</th>
                                    <th>末端设备ID</th>
                                    <th>末端设备名称</th>
                                    <th>说明</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <volist name="list" id="mlist">
                                    <tr>
                                        <!--<td>{$mlist[id]}</td>-->
                                        <td class="index" data-id="{$mlist.id}">{$mlist.sorts}</td>
                                        <td>{$mlist[sensor_code]}</td>
                                        <td>{$mlist[sensor_name]}</td>
                                        <td>{$mlist[sensor_dec]}</td>
                                        <td> <a href="{:U('sensor_edit',array('id'=>$mlist[id]))}">编辑</a>&nbsp;&nbsp;
                                            |&nbsp;&nbsp;
                                            <a href=""
                                            data-toggle="modal" data-id="{$mlist[sensor_code]}" data-animation="bounce" data-target="#editModal">设置参数</a>&nbsp;&nbsp;
                                            |&nbsp;&nbsp;

                                            <a href="javascript:if(confirm('确认删除？'))location='{:U('sensor_deletes',array('id'=>$mlist[id]))}'">删除</a>

                                            |&nbsp;&nbsp;<a href="javascript:if(confirm('确认复制？'))location='{:U('sensor_copys',array('id'=>$mlist[id]))}'">复制</a>

                                        </td>
                                    </tr>
                                </volist>
                                <tr>
                                    <td style="text-align:left" colspan="2"> </td>
                                    <td style="text-align:center" colspan="8" id="pages">{$page}</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
           <div class="modal fade bd-example-modal-xl" id="editModal" tabindex="-1" role="dialog"
                                aria-labelledby="editModal" aria-hidden="true">
                                <div class="modal-dialog modal-xl" role="document">
                                    <div class="modal-content">


                                    </div>
                                </div>
                            </div>
</block>
<block name="myscript">
 <script src="__PUBLIC__/web/js/jquery-ui.min.js"></script>
 <script src="__PUBLIC__/assets/plugins/repeater/jquery.repeater.min.js"></script>    
<script>
   
    $(function(){
        //表格排序
        var fixHelperModified = function(e, tr) {
        var $originals = tr.children();
        var $helper = tr.clone();
        $helper.children().each(function(index) {
            $(this).width($originals.eq(index).width())
        });
        return $helper;
    },
        updateIndex = function(e, ui) {
            var data = [];
            $('td.index', ui.item.parent()).each(function (i) {
                $(this).html(i + 1);
                obj = {};
                obj.id = $(this).data('id');
                obj.sort = i + 1;
                data.push(obj);
            });
            var url = "{:U('saveSort')}";
            $.post(url, {data: data}, function(res){
                if(res == '1'){
                    notify('');
                    notify('success','提示','排序保存成功！');
                } else {
                    notify('error','提示','排序保存失败！');
                }
            });
        };

        $("#sort tbody").sortable({
            helper: fixHelperModified,
            stop: updateIndex,
            placeholder: "widget-placeholder",
        }).disableSelection();
    });
      
    $('#editModal').on('show.bs.modal', function (e) {
            var obj = $(e.relatedTarget);
            var sensor_code = obj.data('id');;
            
            var url = "{:U('sensor_param','','')}/sensor_code/" + sensor_code;
            $.ajax({
                type: 'GET',
                url: url
            }).then(function (data) {
                $('.modal-content').html(data);

            });
        });
</script>
</block>